home *** CD-ROM | disk | FTP | other *** search
- #ifdef HAS_PIPE
- void
- do_pipe(TARG, rstab, wstab)
- STR *TARG;
- STAB *rstab;
- STAB *wstab;
- {
- register STIO *rstio;
- register STIO *wstio;
- int fd[2];
-
- if (!rstab)
- goto badexit;
- if (!wstab)
- goto badexit;
-
- rstio = stab_io(rstab);
- wstio = stab_io(wstab);
-
- if (!rstio)
- rstio = stab_io(rstab) = stio_new();
- else if (rstio->ifp)
- do_close(rstab,FALSE);
- if (!wstio)
- wstio = stab_io(wstab) = stio_new();
- else if (wstio->ifp)
- do_close(wstab,FALSE);
-
- if (pipe(fd) < 0)
- goto badexit;
- rstio->ifp = fdopen(fd[0], "r");
- wstio->ofp = fdopen(fd[1], "w");
- wstio->ifp = wstio->ofp;
- rstio->type = '<';
- wstio->type = '>';
- if (!rstio->ifp || !wstio->ofp) {
- if (rstio->ifp) fclose(rstio->ifp);
- else close(fd[0]);
- if (wstio->ofp) fclose(wstio->ofp);
- else close(fd[1]);
- goto badexit;
- }
-
- str_sset(TARG,&str_yes);
- return;
-
- badexit:
- str_sset(TARG,&str_undef);
- return;
- }
- #endif
-
-